<?php

namespace IMT\UserBundle\Entity;
use FOS\UserBundle\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Model\GroupableInterface;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * @ORM\Table(name="user")
 * @ORM\Entity
 */
class User extends BaseUser
{
    /**
    * @ORM\Id
    * @ORM\Column(type="integer")
    * @ORM\generatedValue(strategy="AUTO")
    */
    protected $id;

    /**
     * @ORM\ManyToMany(targetEntity="IMT\UserBundle\Entity\Team", inversedBy="users")
     * @ORM\JoinTable(name="link_user_team",
     *      joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
     *      inverseJoinColumns={@ORM\JoinColumn(name="team_id", referencedColumnName="id")}
     * )
     */
    protected $teams;
    
    /**
     * @ORM\ManyToMany(targetEntity="IMT\EventBundle\Entity\BaseEvent", mappedBy="owners", cascade={"persist","update"})
     */
    private $events;
    
    /**
     * @ORM\OneToMany(targetEntity="IMT\AccountBundle\Entity\Account", mappedBy="user", cascade={"all"})
     */
    private $accounts;
    
    /**
     * @ORM\OneToMany(targetEntity="IMT\UserBundle\Entity\Contact", mappedBy="user", cascade={"update"})
     */
    private $profils;
    
    /**
     * @ORM\OneToMany(targetEntity="IMT\UserBundle\Entity\GroupContact", mappedBy="user")
     */
    private $groupsContact;
    
    /**
     * Constructor
     */
    public function __construct()
    {
    	$this->teams = new \Doctrine\Common\Collections\ArrayCollection();
    	$this->events = new \Doctrine\Common\Collections\ArrayCollection();
    	$this->accounts = new \Doctrine\Common\Collections\ArrayCollection();
    	$this->profils = new \Doctrine\Common\Collections\ArrayCollection();
    	$this->groupsContact = new \Doctrine\Common\Collections\ArrayCollection();
    }

    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }
    
/**
     * get expired
     *
     * Implements AdvancedUserInterface
     *
     * @return Boolean true if the user's account is non expired, false otherwise
     */
    public function getTimeExpired()
    {
    	if (null !== $this->expiresAt)
        	return date('d/m/Y',$this->expiresAt->getTimestamp());
        return 'non défini';
    }
    
	/**
     * Checks whether the user's account is going to expired.
     *
     * Implements AdvancedUserInterface
     *
     * @return Boolean true if the user's account is going expired, false otherwise
     */
    public function isAccountGoingExpired()
    {
        if (null !== $this->expiresAt) {
            return true;
        }

        return false;
    }

    /**
     * Checks whether the user is locked.
     *
     * Implements AdvancedUserInterface
     *
     * @return Boolean true if the user is not locked, false otherwise
     */
    public function isAccountNonLocked()
    {
        return !$this->locked;
    }

    /**
     * Set salt
     *
     * @param String
     */
    public function setSalt($salt)
    {
    	$this->salt = $salt;
    }
    
    /**
     * Add teams
     *
     * @param IMT\UserBundle\Entity\Team $teams
     */
    public function addTeam(\IMT\UserBundle\Entity\Team $team)
    {
        $this->teams[] = $team;
    }
    
    /**
     * Get teams
     *
     * @return Doctrine\Common\Collections\Collection 
     */
    public function getTeams()
    {
        return $this->teams;
    }
    
    /**
     * Add events
     *
     * @param IMT\EventBundle\Entity\BaseEvent $event
     */
    public function addEvent(\IMT\EventBundle\Entity\BaseEvent $event)
    {
        $this->events[] = $event;
    }

    /**
     * Get events
     *
     * @return IMT\EventBundle\Entity\BaseEvent
     */
    public function getEvents()
    {
        return $this->events;
    }

    /**
     * Add accounts
     *
     * @param IMT\AccountBundle\Entity\Account $accounts
     */
    public function addAccount(\IMT\AccountBundle\Entity\Account $accounts)
    {
        $this->accounts[] = $accounts;
    }

    /**
     * Get accounts
     *
     * @return Doctrine\Common\Collections\Collection 
     */
    public function getAccounts()
    {
        return $this->accounts;
    }
    
    /**
     * Add profils
     *
     * @param IMT\UserBundle\Entity\Contact $participant
     */
    public function addProfil(\IMT\UserBundle\Entity\Contact $contact)
    {
        $this->profils[] = $contact;
    }

    /**
     * Get profils
     *
     * @return Doctrine\Common\Collections\Collection 
     */
    public function getProfils()
    {
        return $this->profils;
    }
    
    /**
     * Add groupsContact
     *
     * @param IMT\UserBundle\Entity\GroupContact $groupsContact
     */
    public function addGroupContact(\IMT\UserBundle\Entity\GroupContact $groupsContact)
    {
    	$this->groupsContact[] = $groupsContact;
    }
    
    /**
     * Get groupsContact
     *
     * @return Doctrine\Common\Collections\Collection
     */
    public function getGroupsContact()
    {
    	return $this->groupsContact;
    }
}